﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestJqGrid.aspx.cs" Inherits="HMS.PL.Forms.TestJqGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../Scripts/jquery-1.6.1.js"></script>
    <link type="text/css" rel="stylesheet" href="../themes/ui-lightness/jquery-ui-1.8.16.custom.css" />
    <link type="text/css" href="../themes/ui-lightness/jquery.ui.all.css" rel="stylesheet" />
    <link type="text/css" rel="stylesheet" href="../Style/!style1.css" />
    <%--jqgrid files--%>
    <link type="text/css" rel="stylesheet" href="../css/ui.jqgrid.css" />
    <link type="text/css" rel="stylesheet" href="../css/ui.multiselect.css" />
    <link type="text/css" rel="stylesheet" href="../themes/redmond/jquery-ui-1.8.1.custom.css" />
    <script src="../Scripts/jquery.layout-latest.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.locale-en.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jqModal.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.base.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.common.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.formedit.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.inlinedit.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.jqueryui.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jquery.contextmenu.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/jquery.tablednd.js" type="text/javascript"></script>
    <%-- <script src="../Scripts/jqgrid/grid.formedit.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.inlinedit.js" type="text/javascript"></script>--%>
    <script src="../Scripts/jqgrid/jqDnR.js" type="text/javascript"></script>
    <script src="../Scripts/jqgrid/grid.filter.js" type="text/javascript"></script>
    <script src="../Scripts/simpleresizabletables.js" type="text/javascript"></script>
    <%--     jquery-ui-1.8.1.custom.css--%>
    <%--jqgrid files--%>
    <script type="text/javascript" src="../Scripts/formsScript/welcome.js"></script>
    <script type="text/javascript" src="../Scripts/formsScript/master.js"></script>
    <script type="text/javascript" src="../Scripts/formsScript/addRelation.js"></script>
    <script type="text/javascript" src="../Scripts/jqgrid/jquery.searchFilter.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript">

        jQuery(document).ready(function () {
            // debugger;

            //fill grid of columns
            $.ajax({
                async: true,
                type: 'GET',
                url: "ConfigCallback.aspx?operation=get_SourceData",
                data: "",
                dataType: "json",
                success: function (result) {
                    //debugger;
                    $("#dataGrid").GridUnload(); // destroy the grid saving the table and pager
                    var editurl = "";
                    //call fill grid for dimension table          
                    fillgridCommon(result, "#dataGrid", "#pager", "800px", "100%", "Table Data", editurl);
                },
                error: function (x, e) {
                  //debugger;
                    alert(x.readyState + " " + x.status + " " + e.msg);
                }
            });

          //debugger;
//            jQuery("#dataGrid").jqGrid('navGrid',  "#pager", 
//                {}, //options
//                {height:280,reloadAfterSubmit:false}, // edit options
//                {height:280,reloadAfterSubmit:false}, // add options
//                {reloadAfterSubmit:false}, // del options
//                {//complex search
//                    multipleSearch: true,
//                    multipleGroup: true,
//                    showQuery: true
//                }
//             };

            jQuery("#dataGrid").jqGrid('navGrid', '#pager',
                {}, //options
                {}, // edit options
                {}, // add options
                {}, // del options
                 {//complex search
                    multipleSearch: true,
                    multipleGroup: false,
                    showQuery: true
                  }
                );


            //jQuery("#dataGrid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: true });

            //dimtable_name = "M_CONTACTS";
            //list_id = "5";
            ////debugger;

            //            $.ajax({
            //                async: false,
            //                type: 'GET',
            //                url: "MasterCallback.aspx?operation=get_coldataURL&dimtable_name=" + dimtable_name + "&list_id=" + list_id,
            //                data: "",
            //                dataType: "json",
            //                success: function (result) {

            //                   // //debugger;
            //                    var colD = result.datarow, colN = result.columns, colM = result.colModelList;
            //                    //$("#dataGrid").GridUnload(); // destroy the grid saving the table and pager

            //                    jQuery("#dataGrid").jqGrid({
            //                        url: "MasterCallback.aspx?operation=get_griddataURL&dimtable_name=" + dimtable_name + "&list_id=" + list_id,
            //                        datatype: 'json',
            //                        colNames: colN,
            //                        colModel: colM,
            //                        rowNum: 10,
            //                        //rowList: [10, 20, 30],
            //                        pager: '#pager',
            //                        sortname: 'contact_id',
            //                        viewrecords: true,
            //                        sortorder: 'desc',
            //                        width:800,
            //                        caption: 'JSON Example',
            //                        loadComplete: function (data) {
            //                           // //debugger;
            //                        },
            //                        loadError: function (xhr, status, error) {
            //                            ////debugger;
            //                            alert('error');
            //                        }
            //                    });

            //                    jQuery("#dataGrid").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true });

            //                },
            //                error: function (x, e) {
            //                    ////debugger;
            //                    alert(x.readyState + " " + x.status + " " + e.msg);
            //                }
            //            });
        });       
              
    </script>
    <%-- <script type="text/javascript">

        jQuery(document).ready(function () {

            dimtable_name = "M_CONTACTS";
            list_id = "5";
            ////debugger;

            $.ajax({
                async: false,
                type: 'GET',
                url: "MasterCallback.aspx?operation=get_coldataURL&dimtable_name=" + dimtable_name + "&list_id=" + list_id,
                data: "",
                dataType: "json",
                success: function (result) {

                   // //debugger;

                    var colD = result.datarow, colN = result.columns, colM = result.colModelList;
                    $("#dataGrid").GridUnload(); // destroy the grid saving the table and pager

                    $('#dataGrid').jqGrid({
                        datatype: function () {
                            $.ajax({

                                url: "MasterCallback.aspx?operation=get_griddataURL&dimtable_name=" + dimtable_name + "&list_id=" + list_id,
                                //data: "{}",  // For empty input data use "{}", 
                                dataType: "json",
                                type: "POST",
                                mtype: 'GET', 
                                prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd"},
                                ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
                                contentType: "application/json; charset=utf-8",
                                viewrecords: true,                              
                                jsonReader: {
                                    root: "rows",
                                    page: "page",
                                    total: "total",
                                    records: "records",
                                    repeatitems: false,
                                    userdata: "userdata"
                                },
                                complete: function (jsondata, stat) {
                                    //debugger;
                                    //alert("tt");
                                    if (stat == "success") {
                                        ////debugger;
                                        var thegrid = jQuery("#dataGrid")[0];
                                        thegrid.addJSONData(JSON.parse(jsondata.responseText));
                                    }
                                },
                                error: function (x, e) {
                                    //debugger;
                                    alert(x.readyState + " " + x.status + " " + e.msg);
                                }

                            });
                        },
                        colNames: colN,
                        colModel: colM,
                        pager: jQuery('#pager'),
                        rowNum: 10,
                        rowList: [10, 20, 30],
                        //sortname: 'Name',
                        //sortorder: 'desc',
                        viewrecords: true,
                        //imgpath: 'jqGrid-3.4.3/themes/coffee/images',
                        caption: 'jqGrid First Grid',
                        width: 900
                    }).navGrid(pager, { edit: true, add: false, del: false, search: false });

                },
                error: function (x, e) {
                    //debugger;
                    alert(x.readyState + " " + x.status + " " + e.msg);
                }
            });


        });

        //     function loadGriddata() {

        //        $.ajax({
        //            async: true,
        //            type: 'GET',
        //            url: "MasterCallback.aspx?operation=get_griddataURL&dimtable_name=" + dimtable_name + "&list_id=" + list_id,
        //            data: "",
        //            dataType: "json",
        //            success: function (result) {
        //                ////debugger;
        //                var colD = result.datarow, colN = result.columns, colM = result.colModelList;
        //                $("#dataGrid").GridUnload(); // destroy the grid saving the table and pager

        //                jQuery("#dataGrid").jqGrid({
        //                    data: colD,
        //                    datatype: 'local',
        //                    gridview: true,
        //                    colNames: colN,
        //                    colModel: colM,
        //                    caption: "Master Data",
        //                    editurl: "MasterCallback.aspx?dimtable_name=" + dimtable_name + "&list_id=" + list_id,
        //                    rowNum: 10,
        //                    pager: '#pager',
        //                    sortname: result.primarykey,
        //                    sortorder: "desc",
        //                    width: "100%",
        //                    height: "100%",
        //                    scrollOffset: 18,
        //                    closeAfterEdit: true,
        //                    ignoreCase: true,
        //                    loadComplete: function (data) {
        //                        // //debugger;
        //                        jQuery("#dataGrid").hideCol(result.primarykey);
        //                    },
        //                    loadError: function (xhr, status, error) {
        //                        ////debugger;
        //                        alert('error');
        //                    }
        //                });

        //                navGridd();

        //            },
        //            error: function (x, e) {
        //                //debugger;
        //                alert(x.readyState + " " + x.status + " " + e.msg);
        //            }
        //        });     
              
    </script>--%>
    <script type="text/javascript">

        //        jQuery(document).ready(function () {
        //            ////debugger;
        //            //submit button click
        //            $("#MSubmit_M").click(function () {
        //                loadgriddata();
        //            });

        //            dimtable_name = "M_EMPLOYEES";
        //            list_id = "3";
        //            loadGriddata_();

        //            // set the names of the template
        //            //            "tmplNames" : ["Template One", "Template Two"],
        //            //            // set the template contents
        //            //            "tmplFilters": [template1, template2]


        //            $("#Button1").click(function () {
        //                //debugger;
        //                //alert("l");
        //                //Show_Search();
        //                var template1 =
        //                {
        //                    "groupOp": "AND",
        //                    "rules": [{ "field": "first_name", "op": "eq", "data": "Client 1" },
        //                              { "field": "first_name", "op": "bw", "data": "aa" }
        //                             ]
        //                };

        //                //                "{   
        //                //                     \"groupOp\":\"OR\",   
        //                //                     \"rules\":   
        //                //                      [   
        //                //                       {\"field\":\"id\",\"op\":\"eq\",\"data\":\"1\"},   
        //                //                       {\"field\":\"id\",\"op\":\"eq\",\"data\":\"2\"},   
        //                //                       {\"field\":\"id\",\"op\":\"eq\",\"data\":\"3\"},   
        //                //                       {\"field\":\"id\",\"op\":\"eq\",\"data\":\"5\"}   
        //                //                      ]   
        //                //                }"  


        //                //filter example

        //                //                    var filters = 
        //                //                       {
        //                //                        "groupOp":"OR",
        //                //                        "rules":[{"field":"a.id","op":"eq","data":"1"}],
        //                //                        "groups":[
        //                //                             {
        //                //                                 "groupOp":"AND",
        //                //                                 "rules":[{"field":"a.id","op":"eq","data":"2"}],
        //                //                                 //"groups":[...]
        //                //                             }
        //                //                         ]
        //                //                    };



        //                var filters =
        //                                       {
        //                                           "groupOp": "OR",
        //                                           "rules": [{ "field": "a.id", "op": "eq", "data": "1"}],
        //                                           "groups": [
        //                                             {
        //                                                 "groupOp": "AND",
        //                                                 "rules": [{ "field": "a.id", "op": "eq", "data": "2"}]//,
        //                                                 //"groups":[...]
        //                                             }
        //                                         ]
        //                                       };


        //                var template2 = { "groupOp": "AND", "rules": [{ "field": "first_name", "op": "eq", "data": "Client 2" }, { "field": "first_name", "op": "bw", "data": "jj"}] };

        //                //(((first_name = "test 3" AND first_name = "test 4") AND first_name = "test 2") OR first_name = "test 1")

        //                var template3 = { "groupOp": "OR",
        //                    "rules": [{ "field": "last_name", "op": "eq", "data": "test1"}],
        //                    "groups": [
        //                                                {
        //                                                    "groupOp": "AND",
        //                                                    "rules": [{ "field": "last_name", "op": "eq", "data": "test 2"}],
        //                                                    "groups": [{
        //                                                        "groupOp": "AND",
        //                                                        "rules": [
        //                                                                           { "field": "last_name", "op": "eq", "data": "test 3" },
        //                                                                           { "field": "last_name", "op": "bw", "data": "test 4" },
        //                                                                        ]
        //                                                    }]
        //                                                }
        //                                            ]
        //                };


        //                var pSearch =
        //                {
        //                    
        //                    drag:false,
        //                    multipleSearch: true,
        //                    multipleGroup: true,
        //                    showQuery: false,
        //                    showRel: true,
        //                    overlay: false//, /* any parameters */
        //                    // set the names of the template 
        //                   // "tmplNames": ["Template One", "Template Two", "Template Three"],
        //                    // set the template contents 
        //                   // "tmplFilters": [template1, template2, template3]//,
        //                    //sFilter: filters
        //                };

        //                ////debugger;
        //                $("#dataGrid").jqGrid("searchGrid", pSearch);

        //                //to set filter for edit mode
        //                $("#fbox_dataGrid").jqFilter('addFilter', eval(template3));


        //                // $("#fbox_dataGrid_query").hide(); //"fbox_dataGrid_query"
        //                $("#fbox_dataGrid_search").hide(); //"fbox_dataGrid_search"
        //                //searchmodfbox_dataGrid
        //                $("#fbox_dataGrid_search").css("left", "10px");
        //                $(".ui-jqdialog-title")[0].innerHTML = "Query..."; //"ui-jqdialog-title"
        //                // input.removeAttr("title") //searchmodfbox_dataGrid

        //                //alert($("#searchmodfbox_dataGrid"));
        //                $("#searchmodfbox_dataGrid").removeAttr("role");
        //                //$('#searchmodfbox_dataGrid').removeClass('ui-jqdialog');

        //                ////debugger;
        //                //get filter object
        //                var fl = $("#" + "fbox_dataGrid"),
        //                sdata = {}, res,
        //                filters = fl.jqFilter('filterData');
        //                ///////
        //                //toSQLString
        //                var query =fl.jqFilter('toSQLString');
        //                //
        //                ////debugger;
        //                //filters1 = $("#fbox_dataGrid").jqFilter('filterData');

        //                //$("#test").show();
        //                // $("#dataGrid").searchFilter([{ text: "Field 1", value: "field1" }, { text: "Field 2", value: "field2"}], { onSearch: myFilterRuleReceiverFn, onReset: myFilterResetFn });
        //            });

        //            //submit button click
        //            $("#Button2").click(function () {
        //                ////debugger;
        //                dimtable_name = "M_EMPLOYEES";
        //                list_id = "3";
        //                loadGriddata_();
        //                // $("#test").hide(); //gview_dataGrid
        //                // $("#gview_dataGrid").hide(); //pg_pager
        //                // $("#pager").hide();
        //            });

        //        });

        //        function Show_Search() {
        //            $("#dataGrid").searchFilter([{ text: "Field 1", value: "field1" }, { text: "Field 2", value: "field2"}], { onSearch: myFilterRuleReceiverFn, onReset: myFilterResetFn });
        //        }

        //        function loadGriddata_() {
        //            //var list_id = "2";
        //            // var dimtable_name = "M_PRODUCTS";

        //            $.ajax({
        //                async: true,
        //                type: 'GET',
        //                url: "MasterCallback.aspx?operation=get_griddata&dimtable_name=" + dimtable_name + "&list_id=" + list_id,
        //                data: "",
        //                dataType: "json",
        //                success: function (result) {
        //                   // //debugger;
        //                    var colD = result.datarow, colN = result.columns, colM = result.colModelList;
        //                    $("#dataGrid").GridUnload(); //destroy the grid saving the table and pager

        //                    jQuery("#dataGrid").jqGrid({
        //                        datatype: 'local',
        //                        colNames: colN,
        //                        colModel: colM,
        //                        // pager: '#pager',
        //                        // sortname: result.primarykey,
        //                        // sortorder: "desc",
        //                        //width: "100%",
        //                        width: "10px",
        //                        // scrollOffset: 18,                       
        //                        ignoreCase: true,
        //                        loadComplete: function (data) {
        //                            ////debugger;
        //                            jQuery("#dataGrid").hideCol(result.primarykey);
        //                            jQuery("#dataGrid").setGridWidth(400, true);
        //                            $("#gview_dataGrid").hide(); //pg_pager
        //                            //$("#pager").hide();
        //                            $('#gbox_dataGrid').removeClass('ui-widget-content');

        //                        },
        //                        loadError: function (xhr, status, error) {
        //                            ////debugger;
        //                            alert('error');
        //                        }
        //                    });
        //                    ////debugger;
        //                    // navGridd();
        //                    // jQuery("#dataGrid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: true });

        //                },
        //                error: function (x, e) {
        //                    //debugger;
        //                    alert(x.readyState + " " + x.status + " " + e.msg);
        //                }
        //            });

        //            // //debugger;
        //            //            jQuery("#dataGrid").jqGrid('navGrid', '#pager',
        //            //            { edit: false, add: false, del: false, search: true },
        //            //                {},
        //            //                {},
        //            //                {},
        //            //                {
        //            //                    multipleSearch: true,
        //            //                    multipleGroup: true,
        //            //                    showQuery: true
        //            //                }
        //            //            );
        //        }

        //        function refreshgrid(result, tblname) {
        //            // //debugger;
        //            var colD = result.datarow; //, colN = result.columns, colM = result.colModelList;
        //            //clear grid data
        //            $(tblname).jqGrid("clearGridData", true);
        //            //refresh jqgrid
        //            jQuery(tblname).jqGrid('setGridParam', { datatype: 'local', data: colD }).trigger("reloadGrid");
        //        } 
                  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="margin-left: 0px; text-align: left;">
            <span style="width: 25px; text-align: left;">Master</span>
            <%--   <select style="width: 140px;" id="drp_mst" name="drp_mst">
            </select>&nbsp;&nbsp;
            <input id="MSubmit_M" type="button" style="height: 24px; margin: 5px auto;" value="submit" />&nbsp;<br />
            <br />--%>
            <input id="Button1" type="button" style="height: 24px; margin: 5px auto;" value="Search" />&nbsp;<br />
            <br />
            <br />
            <input id="Button2" type="button" style="height: 24px; margin: 5px auto; display: none;"
                value="Master" />&nbsp;<br />
            <font id="fprec" style='font-weight: bold; color: #FF0000; vertical-align: bottom;'>
                *</font>
            <%--<br />--%>
            <%--    <span><div style="overflow: auto;" class="searchFilter" id="fbox_dataGrid"></div>
            
            </span>--%>
            <input id="Button3" type="button" style="height: 24px; margin: 5px auto;" value="Grid Url" />&nbsp;<br />
        </div>
        <table id="dataGrid" class="scroll" cellpadding="0" cellspacing="0">
        </table>
        <div id="pager" class="scroll">
        </div>
        <img style="vertical-align: text-bottom" src="../Images/expert-dimensions-logo.PNG">
    </div>
    </form>
</body>
</html>
